package mashuaiproject.mashuaiproject.mapper;

import mashuaiproject.mashuaiproject.model.Comments;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface CommentMapper {

    @Insert("insert into comment(parent_id,type,commentator,gmt_create,gmt_modified,content) values(" +
            "#{parent_id},#{type},#{commentator},#{gmt_create},#{gmt_modified},#{content})")
    int insertComment(Comments comments);

    @Select("select *from comment where parent_id=#{parent_id}")
    Comments selectByPrimaryKey(@Param("parent_id") Integer parent_id);

    //查找所有的文章id一级评论
    @Select("select *from comment where parent_id=#{parent_id} and type=1 ORDER BY gmt_create desc")
    List<Comments> selectListCommentType_One(@Param("parent_id") Integer id);
    //查找一级评二级评论的数量
    @Select("select count(1) from commentson where father_id=#{father_id}")
    int getCommentSonConut(@Param("father_id") Integer id);
    //查找一级评论的点赞上升数量
    @Select("select fabulous_up from comment where id=#{id}")
    int getFabulousUpConut(@Param("id") Integer id);
    //查找一级评论的点赞x下升数量
    @Select("select fabulous_down from comment where id=#{id}")
    int getFabulousDownConut(@Param("id") Integer id);

    @Update("update comment set commentson_count=commentson_count+1 where id=#{id} ")
    int updateCommetSonCount(@Param("id") Integer father_id);//更新耳机评论的数量
    @Select("select commentson_count from comment where id=#{id} ")
    int selectCommetSonCount(@Param("id") Integer father_id);//查处二级评论的数量

    @Select("select commentator from comment where id=#{father_id} ")
    Integer getReceiverd(@Param("father_id") Integer father_id);

    @Select("select creator from quesions where id=#{parent_id} ")
    int getReceiverd2(@Param("parent_id") Integer parent_id);

    @Select("select id from comment where id=#{father_id}")
    Integer sleectById(@Param("father_id") Integer father_id);
    @Select("select *from comment where commentator=#{id} limit #{offset},#{size}")
    List<Comments> selectOneComments(@Param("id") Integer id,@Param("offset")Integer offset,@Param("size")Integer size);

    @Select("select count(1) from comment where commentator=#{id}")
    Integer getCommentOneComment(Integer id);

    @Select("select *from comment where commentator=#{id} order by  gmt_create asc  limit #{offset},#{size}")
    List<Comments> selectOneCommentstimeUp(@Param("id") Integer id,@Param("offset")Integer offset,@Param("size")Integer size);

    @Select("select *from comment where commentator=#{id} order by  gmt_create desc  limit #{offset},#{size}")
    List<Comments> selectOneCommentstimeDown(@Param("id") Integer id,@Param("offset")Integer offset,@Param("size")Integer size);

    @Select("select *from comment where commentator=#{id} order by  fabulous_up desc  limit #{offset},#{size}")
    List<Comments> selectOneCommentstimefabulousUp(@Param("id") Integer id,@Param("offset")Integer offset,@Param("size")Integer size);

    @Select("select *from comment where commentator=#{id} order by  fabulous_down desc  limit #{offset},#{size}")
    List<Comments> selectOneCommentstimefabulousDown(@Param("id") Integer id,@Param("offset")Integer offset,@Param("size")Integer size);

}
